home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / test / lib / listres.c < prev    next >
C/C++ Source or Header  |  1992-11-23  |  2KB  |  78 lines

  1.  
  2. /*
  3.  *  RESIDENT.C
  4.  *
  5.  *  Create temporary 'resident' node that LoadSeg()s a program, runs it,
  6.  *  and replies a message.  This node is uniquely named and can only be
  7.  *  used in a non-reentrant fashion.
  8.  *
  9.  *  You create the node, then Execute() the node's name... simple!
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/execbase.h>
  14. #include <exec/ports.h>
  15. #include <exec/memory.h>
  16. #include <libraries/dos.h>
  17. #include <libraries/dosextens.h>
  18.  
  19. typedef struct DosLibrary   DosLibrary;
  20. typedef struct RootNode     RootNode;
  21. typedef struct DosInfo        DosInfo;
  22. typedef struct CommandLineInterface CLI;
  23.  
  24. typedef struct MsgPort        MsgPort;
  25. typedef struct Message        Message;
  26. typedef struct Task        Task;
  27. typedef struct Process        Process;
  28.  
  29. typedef struct SegNode {
  30.     BPTR    NextEntry;
  31.     LONG    UseCount;
  32.     BPTR    SegPtr;
  33.     BPTR    SegName;
  34. } SegNode;
  35.  
  36.  
  37. #define BTOC(bptr, type)  ((type *)((long)(bptr) << 2))
  38. #define CTOB(cptr)  ((BPTR)((long)(cptr) >> 2))
  39.  
  40. /*
  41.  *  Create and return the node, return node name in auxillary argument
  42.  *
  43.  *  When you run a program using this node a message will be returned to
  44.  *  the specified MsgPort when the program exits, containing the exit code.
  45.  *
  46.  *  If you intend to run a program in the background you must create a node
  47.  *  for each program.
  48.  */
  49.  
  50. extern struct ExecBase *SysBase;
  51. extern DosLibrary *DOSBase;
  52.  
  53. main(ac, av)
  54. char *av[];
  55. {
  56.     DosInfo *di = BTOC(((RootNode *)DOSBase->dl_Root)->rn_Info, DosInfo);
  57.     SegNode *sn;
  58.  
  59.     printf("root: %08lx\n", DOSBase->dl_Root);
  60.     printf("info: %08lx\n", di);
  61.     printf("di %08lx di->di_NetHand %08lx\n", di, di->di_NetHand);
  62.  
  63.     for (sn = BTOC(di->di_NetHand, SegNode); sn; sn = BTOC(sn->NextEntry, SegNode)) {
  64.     int namlen = *(unsigned char *)&sn->SegName;
  65.     printf("sn %08lx name %-15.*s seg %08lx ref %ld\n",
  66.         sn,
  67.         namlen,
  68.         (char *)&sn->SegName + 1,
  69.         sn->SegPtr,
  70.         sn->UseCount
  71.     );
  72.     if (ac == 3 && namlen == strlen(av[1]) && strncmp(av[1], (char *)&sn->SegName + 1, namlen) == 0) {
  73.         sn->UseCount = atoi(av[2]);
  74.     }
  75.     }
  76. }
  77.  
  78.